#ifndef THREADPOOLMANAGER_H
#define THREADPOOLMANAGER_H

#pragma once
// #include <ThreadPool.h>
#include "common/constant.h"
#include "ThreadPoolInstance.h"

AMCAX_EXCHANGE_NAMESPACE_BEGIN

namespace InterOp {

class ThreadPoolManager
{
public:
    ~ThreadPoolManager() = default;

    static ThreadPoolManager &GetInstance()
    {
        static ThreadPoolManager instance;
        return instance;
    };

    void InitThreadPool(size_t poolSize) ;

    template<class F, class... Args>
    auto AddWorker(F&& f, Args&&... args) 
        -> std::future<typename std::result_of<F(Args...)>::type>
    {
        if (!isInit) {
            throw std::runtime_error("Threadpool not init");
        }
        return pool_->AddWorker(f,std::forward<Args>(args)...) ;
    }


private:
    ThreadPoolManager() ;

    std::unique_ptr<ThreadPoolInstance> pool_{nullptr};
    bool isInit{false} ;
};

}

AMCAX_EXCHANGE_NAMESPACE_END

#endif